#!/bin/bash
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
custom_rules_file="${script_dir}/custom_rules_list.txt"
rules_script="${script_dir}/rules.sh"
. ${script_dir}/includes/test_utils.sh
. ${script_dir}/includes/log_utils.sh

# 读取 custom_rules_list.txt 中的函数名并执行对应函数
while IFS= read -r line; do
    # 跳过空行
    if [ -z "$line" ]; then
        continue
    fi

    # 执行对应的函数
    if grep -q -F "$line()" "$rules_script"; then
        source "$rules_script"
        "$line"
        result=$?
        if [[ "$result" == "127" ]]; then
            info "${line} not implemented"
        elif [[ "$result" == "0" ]]; then
            access "${line}"
        elif [[ "$result" == "1" ]]; then
            error "${line}"
        elif [[ "$result" == "2" ]]; then
            warn "${line}"
        fi
    else
        echo "Function '$line' not found in $rules_script"
    fi
done < "$custom_rules_file"
